/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.opgea.token.web.dto;

import java.io.Serializable;

import com.opgea.token.domain.constants.ApplicationConstants;
import com.opgea.token.domain.entities.Employee;
import com.opgea.token.domain.interfaces.Marshallable;

/**
 * 
 * @author Ramesh
 */
public class EmployeeDTO implements Serializable, Marshallable<Employee> {

    private static final long serialVersionUID = 4230449721625434409L;
    private Long id;
    private Long companyId;
    private String firstName;
    private String middleInitial;
    private String lastName;

    private String emailId;
    private String phone1;
    private String phone2;

    private String empCode;
    private Long destinationId;
    private String destinationName;

    public EmployeeDTO() {
    }

    public EmployeeDTO(Long id, Long companyId, String firstName,
	    String middleInitial, String lastName, String emailId,
	    String phone1, String phone2, String empCode, Long destinationId,
	    String destinationName) {
	this.id = id;
	this.companyId = companyId;
	this.firstName = firstName;
	this.middleInitial = middleInitial;
	this.lastName = lastName;
	this.emailId = emailId;
	this.phone1 = phone1;
	this.phone2 = phone2;
	this.empCode = empCode;
	this.destinationId = destinationId;
	this.destinationName = destinationName;
    }

    public Long getCompanyId() {
	return companyId;
    }

    public void setCompanyId(Long companyId) {
	this.companyId = companyId;
    }

    public Long getDestinationId() {
	return destinationId;
    }

    public void setDestinationId(Long destinationId) {
	this.destinationId = destinationId;
    }

    public String getDestinationName() {
	return destinationName;
    }

    public void setDestinationName(String destinationName) {
	this.destinationName = destinationName;
    }

    public String getEmailId() {
	return emailId;
    }

    public void setEmailId(String emailId) {
	this.emailId = emailId;
    }

    public String getEmpCode() {
	return empCode;
    }

    public void setEmpCode(String empCode) {
	this.empCode = empCode;
    }

    public String getFirstName() {
	return firstName;
    }

    public void setFirstName(String firstName) {
	this.firstName = firstName;
    }

    public Long getId() {
	return id;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public String getLastName() {
	return lastName;
    }

    public void setLastName(String lastName) {
	this.lastName = lastName;
    }

    public String getMiddleInitial() {
	return middleInitial;
    }

    public void setMiddleInitial(String middleInitial) {
	this.middleInitial = middleInitial;
    }

    public String getPhone1() {
	return phone1;
    }

    public void setPhone1(String phone1) {
	this.phone1 = phone1;
    }

    public String getPhone2() {
	return phone2;
    }

    public void setPhone2(String phone2) {
	this.phone2 = phone2;
    }

    @Override
    public void marshall(Employee employee) {
	this.id = employee.getId();
	this.firstName = employee.getFirstName();
	this.middleInitial = employee.getMiddleInitial();
	this.lastName = employee.getLastName();
	this.emailId = employee.getEmailId();
	this.empCode = employee.getEmpCode();
	if (employee.getCompany() != null) {
	    this.companyId = employee.getCompany().getId();
	}
	if (employee.getDestination() != null) {
	    this.destinationId = employee.getDestination().getId();
	    this.destinationName = employee.getDestination().getName();
	}
	if (employee.getPhoneNo() != null) {
	    this.setPhone1(employee.getPhoneNo());
	    this.setPhone2(ApplicationConstants.NO_DATA);
	}
    }

    @Override
    public Employee unmarshall(Employee employee) {
	if (this.getId() > 0) {
	    employee.setId(this.getId());
	}
	employee.setFirstName(this.getFirstName());
	employee.setMiddleInitial(this.getMiddleInitial());
	employee.setLastName(this.getLastName());
	employee.setEmpCode(this.getEmpCode());
	employee.setEmailId(this.getEmailId());
	employee.setPhoneNo(this.getPhone1());
	if (employee.getCompany() != null && this.companyId != null
		&& this.companyId > 0) {
	    employee.getCompany().setId(this.companyId);
	}
	if (employee.getDestination() != null && this.destinationId != null
		&& this.destinationId > 0) {
	    employee.getDestination().setId(this.destinationId);
	    employee.getDestination().setName(this.destinationName);
	}
	return employee;
    }

    @Override
    public String toString() {
	return "EmployeeDTO{" + "id=" + id + ", companyId=" + companyId
		+ ", firstName=" + firstName + ", middleInitial="
		+ middleInitial + ", lastName=" + lastName + ", emailId="
		+ emailId + ", phone1=" + phone1 + ", phone2=" + phone2
		+ ", empCode=" + empCode + ", destinationId=" + destinationId
		+ ", destinationName=" + destinationName + '}';
    }

}
